<template>
    <view class="page">
        <view class="context">
            <view class="mb2">推荐理由</view>
            <view class="mb2">
                <view>
                    <custom-textarea v-model="casecontext" :maxlength="16383"></custom-textarea>
                </view>
            </view>


            <view class="button-end">
                <uv-button :custom-style="submitButton" @click="submit">{{ $t('提交') }}</uv-button>
            </view>
        </view>
    </view>
</template>

<script setup lang="ts">
import api from '@/api';
import type { Iuser } from '@/interface';
import { submitButton } from '@/util/style';
import { onLoad } from '@dcloudio/uni-app';
import dayjs from 'dayjs';
import type { Ref } from 'vue';
import { inject, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import CustomTextarea from '@/components/custom-textarea.vue';
const id = ref()
const $t = useI18n().t
const casecontext = ref()
onLoad((query) => {
    id.value = query?.id
})
const user = inject<Ref<Iuser>>('user')
async function submit() {
    api('/wechat/comment/setcase', {
        id: id.value,
        casecontext: casecontext.value,
        iscase: 1,
        casetime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
        caseuserid: user?.value.tenant_user_id,
        caseusername: user?.value.name
    }).then(e => {
        uni.showToast({
            title: $t('设置完成'),
            duration: 2000,
        });
        uni.navigateBack()
    }).catch(e => {
        uni.showToast({
            title: $t('设置失败'),
            duration: 2000,
            icon: 'error'
        });
    })
}
</script>

<style scoped lang="scss">
.context {
    display: flex;
    flex-direction: column;
    padding: 36rpx;
    font-size: 14px;

    .button-end {
        display: flex;
        width: 100%;
        align-items: center;
        justify-content: center;
    }
}
</style>